/**
 * 
 */
package GUI.main.renderers;

import java.awt.Component;
import java.awt.Dimension;
import java.io.IOException;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import GUI.main.MainClient;

import officeserver.log_error.UserException;
import officeserver.report.Appointment;
import officeserver.users.AccessLevel;
import officeserver.users.PersonalInfo;

/**
 * @author mramsey3
 * 
 */
public class AppointmentListRenderer extends JLabel implements ListCellRenderer {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing
     * .JList, java.lang.Object, int, boolean, boolean)
     */
    @Override
    public Component getListCellRendererComponent(JList list, Object value,
	    int arg2, boolean isSelected, boolean arg4) {
	Appointment appointment = (Appointment) value;
	try {
	    MainClient.getConnection().userSearch(appointment.getPatientID(),
		    AccessLevel.PATIENT);
	} catch (UserException e) {
	    e.printStackTrace();
	}
	catch (IOException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	catch (ClassNotFoundException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

	PersonalInfo pInfoPatient = null;
	try {
	    pInfoPatient = MainClient.getConnection().getSearchPersonalInfo();
	} catch (UserException e1) {
	    e1.printStackTrace();
	}
	catch (IOException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	catch (ClassNotFoundException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	try {
	    MainClient.getConnection().userSearch(appointment.getDoctorID(),
		    AccessLevel.DOCTOR);
	} catch (UserException e) {
	    e.printStackTrace();
	}
	catch (IOException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	catch (ClassNotFoundException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	PersonalInfo pInfoDoctor = null;
	try {
	    pInfoDoctor = MainClient.getConnection().getSearchPersonalInfo();
	} catch (UserException e) {
	    e.printStackTrace();
	}
	catch (IOException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	catch (ClassNotFoundException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	setText(pInfoPatient.getAccessLevel() + ":"
		+ pInfoPatient.getFirstName() + " "
		+ pInfoPatient.getLastName() + " "
		+ pInfoDoctor.getAccessLevel() + ":"
		+ pInfoDoctor.getFirstName() + " " + pInfoDoctor.getLastName());
	if (isSelected) {
	    setBackground(list.getSelectionBackground());
	    setForeground(list.getSelectionForeground());
	} else {
	    setBackground(list.getBackground());
	    setForeground(list.getForeground());
	}
	setEnabled(list.isEnabled());
	setFont(list.getFont());
	setOpaque(true);
	setPreferredSize(new Dimension(getWidth(), 40));

	return this;
    }
}
